<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@include file="/WEB-INF/webpage/common/taglibs.jspf"%>
<!DOCTYPE html>
<html>
<head>
  <title><spring:message code="activiti.model.title" /></title>
  <meta name="decorator" content="list"/>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <script type="text/javascript" src="${staticPath }/uadmin/js/public-add.js"></script>
  <html:css  name="iCheck,Validform,jquery-ztree,easy-ui"/>
  <html:js  name="iCheck,Validform,jquery-ztree,easy-ui,public-js"/>
  <style type="text/css">.row{margin:0;}</style>
  <script type="text/javascript" src="${staticPath}/common/js/window.js"></script>
  <script type="text/javascript" src="${staticPath}/common/js/ztree.js"></script>
  <script type="text/javascript" src="${staticPath}/common/js/initSelect.js"></script>
</head>
<body title="<spring:message code="activiti.model.title" />">
<div class="easyui-layout" fit="true" id="cc" style="width:100%;">
	<div data-options="region:'west',split:true" style="width:15%;" title="流程类型">
		 <div class="zTreeDemoBackground left">
			<ul id="ztree" class="ztree"></ul>
		</div>
	</div>
	<div data-options="region:'center'" title="流程类型">
		<grid:grid id="activitiModelId" url="${adminPath}/activiti/deploy/model/ajaxList" multiselect="false" scrollpage="true" rowNum="30">
			<grid:column label="activiti.model.id" hidden="true"   name="id" width="100"/>
		    <grid:column label="sys.common.opt"  name="opt" formatter="button" width="160"/>
		    <grid:column label="activiti.model.name"  name="name"  query="true" formatter="activitiModelIdNameFormatter"  queryModel="input" width="100"   condition="like" />
		    <grid:column label="activiti.model.key"  name="key" />
		    <grid:column label="activiti.model.discription"  name="discription"  />
		    <grid:column label="activiti.model.type"  name="modelType" />
		    <grid:column label="activiti.model.createtime"  name="createTime" formatter="date" dateformat="yyyy-MM-dd"/>
		    <grid:column label="activiti.model.release.status"  name="status" dict="fb" />
			<grid:button groupname="opt" function="rowConfirm" title="activiti.model.release" tipMsg="你确定要发布该流程模型吗?" outclass="btn-fa-play-circle" url="${adminPath}/activiti/deploy/deployModel?modelId={id}"/>
			<grid:button groupname="opt" function="rowDialogDetailRefresh" title="activiti.taskdef.title" winwidth="70%" winheight="70%" outclass="btn-fa-repeat" url="${adminPath}/activiti/deploy/predef/userTaskList?modelId=\"+row.id+\"" />
			<grid:button title="activiti.model.bindflow"  groupname="opt" function="updateObj" outclass="btn-info" winwidth="70%" winheight="80%" url="${adminPath}/workflow/actmenuorg/modMenuOrg?modelKey=\"+row.key+\"" />
			<grid:button groupname="opt" exp="row.status==1" function="rowDialogDetailRefresh" title="activiti.model.version.monitor" outclass="btn-fa-sign-out" url="${adminPath}/activiti/deploy/predef/list?modelId=\"+row.id+\"" winwidth="80%" winheight="80%"/>
			<grid:button groupname="opt" exp="row.status==0" function="delete" url="${adminPath}/activiti/deploy/delModel?modelId={id}"/>
			<grid:toolbar  function="create_" title="activiti.model.add" btnclass="btn-fa-plus" icon="fa-plus" url="${adminPath}/activiti/deploy/createModel"/>
			<grid:toolbar  function="update_" title="activiti.model.edit" btnclass="btn-fa-file-text-o" icon="fa-file-text-o" url="${adminPath}/activiti/deploy/modeler?modelId={id}" winwidth="100%" winheight="100%"/>
			<grid:toolbar  function="impModel" title="activiti.model.import"  url="${adminPath}/activiti/deploy/impModel" btnclass="btn-fa-file-excel-o" icon="fa-upload" winwidth="100%" winheight="100%"/>
			<grid:toolbar  function="expModel" title="activiti.model.export"  url="${adminPath}/activiti/deploy/modeler?modelId={id}" btnclass="btn-fa-download" icon="fa-download" winwidth="100%" winheight="100%"/>
			<grid:toolbar  function="search"  />
		</grid:grid>
	</div>

<script type="text/javascript">

var gridId = 'activitiModelIdGrid';
var treeObj = null;
var nodeId = null;

/**
 * @description 初始化加载js.<br>
 * @date 2018/8/27.<br>
 * @author zcg .<br>
 */
$(function(){
	var ztreeList = '${ztreeList}';
	ztreeList = $.parseJSON(ztreeList);
	treeObj = $.fn.zTree.init($("#ztree"), setting, ztreeList);
});
 
/**
 * @description 左侧树的相关参数设置.<br>
 * @date 2018/2/24.<br>
 * @author zcg .<br>
 */ 
var setting = {
	callback: {
		onClick: zTreeOnClick
	}
}
 
/**
 * @description 点击左侧的树,触发搜索.<br>
 * @date 2018/2/24.<br>
 * @author zcg .<br>
 */
function zTreeOnClick(event, treeId, treeNode){
	nodeId = treeNode.id;
	search(gridId,{nodeId:nodeId});
}
 
/**
 * @description 新增流程.<br>
 * @date 2018/8/27.<br>
 * @author zcg .<br>
 */
function create_(title,url,gridId,width,height){
 	url = url + '?nodeId='+nodeId;
 	create(title,url,gridId,width,height)
}


/**
 * @description 导入模型.<br>
 * @date 2018/5/31.<br>
 * @author zcg.<br>
 */
function impModel(title,url,gridId,width,height){
	url = url + '?nodeId='+nodeId;
	uploadExcel('导入模型',url,gridId);
}

/**
 * @description 导出模型.<br>
 * @date 2018/5/31.<br>
 * @author zcg.<br>
 */
function expModel(title,url,gridId,width,height){
	var rowData= $("#"+gridId).jqGrid('getGridParam','selrow');
	if(!rowData){
		layer.msg('请选择一条数据',{icon:2});
		return;
	}
	var url = '${adminPath}/activiti/deploy/export/model?modelId='+rowData;
	window.open(url);
}
 
 /**
  * @description 导出模型.<br>
  * @date 2018/5/31.<br>
  * @author zcg.<br>
  */
  function update_(title,url,gridId,width,height){
	  	var rowData= $("#"+gridId).jqGrid('getGridParam','selrow');
		if(!rowData){
			layer.msg('请选择一条数据',{icon:2});
			return;
		}
		url = url.replace('{id}',rowData);
		openDialogDetailRefresh(title,url,gridId,width,height);
  }
  
  /**
   * @description 加载行样式.<br>
   * @date 2018/12/7.<br>
   * @author zcg.<br>
   */
  function activitiModelIdNameFormatter(cellvalue, options, rowdata){
	  return "<a href='javascript:void(0)' style='color: SteelBlue;' onclick='updateModel(\""+rowdata.id+"\")'>"+cellvalue+"</a>";
  }
  
   /**
    * @description 更新模型基本信息.<br>
    * @date 2018/12/7.<br>
    * @author zcg.<br>
    */
  function updateModel(id){
	  var url = "${adminPath}/activiti/deploy/updateModel?id="+id;
	  openDialog("修改",url,gridId,'40%','60%');
  }
</script>